/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Manager_Image_Utils;

import java.awt.Component;
import java.io.File;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.filechooser.FileSystemView;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 *
 * @author PHONG
 */
public class RenderTree extends DefaultTreeCellRenderer {

    //private static final long _serialVersionUID = -7799441088157759804L;

    private FileSystemView _fileSystemView;

    private JLabel _label;

    public RenderTree() {
        _label = new JLabel();
        _label.setOpaque(true);
        _fileSystemView = FileSystemView.getFileSystemView();
    }

    @Override
    public Component getTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean selected,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {

        DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
        File file = (File)node.getUserObject();
        _label.setText(_fileSystemView.getSystemDisplayName(file));
        try {
            _label.setToolTipText(file.getPath());
        } catch (Exception e) {
        }
//      label.setToolTipText(file.getPath());
          Constants c= new Constants();
        if (selected) {
            _label.setBackground(backgroundSelectionColor);
            _label.setForeground(textSelectionColor);
            _label.setIcon(_fileSystemView.getSystemIcon(file));
        
        } else {
            _label.setBackground(backgroundNonSelectionColor);
            _label.setForeground(textNonSelectionColor);
             _label.setIcon(null);
             _label.setIcon(_fileSystemView.getSystemIcon(file));
        }

        return _label;
    }
}